local zhisu = fk.CreateSkill {
  name = "th_zhisu",
}

zhisu:addEffect(fk.EventPhaseProceeding, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zhisu.name) and player.phase == Player.Draw and #player:getPile("$th_alice_renxing") == 0 and not data.phase_end
  end,
  on_use = function(self, event, target, player, data)
    local cards = player.room:getNCards(2)
    player:addToPile("$th_alice_renxing", cards, false, zhisu.name)
    data.phase_end = true
  end
})

zhisu:addEffect(fk.AfterCardsMove, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if not player:isAlive() then return false end
    for _, move in ipairs(data) do
      if move.from == player then
        for _, info in ipairs(move.moveInfo) do
          if info.fromSpecialName == "$th_alice_renxing" and #player:getPile("$th_alice_renxing") == 0 then
            return true
          end
        end
      end
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:drawCards(2, "th_zhisu")
  end,
})

Fk:loadTranslationTable{
  ["th_zhisu"] = "织塑",
  [":th_zhisu"] = "摸牌阶段，若你的武将牌上没有牌，你可以改为将牌堆顶两张牌扣置于你的武将牌上，称为“人形”；当你失去最后一张“人形”后，你摸两张牌。",

  -- ["#th_zhisu-invoke"] = "织塑：你可以少摸任意张牌，然后将牌堆顶的等量张牌扣置于你的武将牌上，称为“人形”",

  ["$th_alice_renxing"] = "人形",
}

return zhisu